﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Strategy.Core.TradeTypes;

namespace Strategy.Core.TradeStreams.Indicators
{
    public class MACDIndicatorStream : AIndicator
    {
        public static string generateID(long lp, long sp) { return "MACD " + lp + ", " + sp; }
        protected EMAIndicatorStream EMAs = null;
        protected EMAIndicatorStream EMAl = null;

        public long LongPeriod { get { return EMAl.Period; } }
        public long ShortPeriod { get { return EMAs.Period; } }


        public override int getLevel()
        {
            return EMAl.getLevel()+1;
        }

        public MACDIndicatorStream(EMAIndicatorStream _short,
                                   EMAIndicatorStream _long)
        {
            EMAs = _short;
            EMAl = _long;
            Interval = EMAs.Interval;
            values = new List<IndicatorValue>();
        }
        protected override double getCalculatedValue(QuoteData qd)
        {
            return EMAl.getByIndexFromEnd(0).Value - EMAs.getByIndexFromEnd(0).Value;
        }

        public override string getID()
        {
            return generateID(LongPeriod, ShortPeriod);
        }
    }
}
